/**

This file is part of MaCI/GIMnet.

MaCI/GIMnet is free software: you can redistribute it and/or modify it 
under the terms of the GNU Lesser General Public License as published 
by the Free Software Foundation, either version 3 of the License, or 
(at your option) any later version.

MaCI/GIMnet is distributed in the hope that it will be useful, but WITHOUT 
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 
FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public 
License for more details.

You should have received a copy of the GNU Lesser General Public 
License along with GIMnet. (See COPYING.LESSER) If not, see 
<http://www.gnu.org/licenses/>.

**/
#include "Wall.h"

TMaterial CWall::WallMaterial=TMaterial(DEFAULT_SURFACE,DEFAULT_DENSITY,(TOGLMaterial){{0.8,0.8,0.6}});

CWall::CWall(CWorld *World, float x1, float y1, float x2, float y2, float width, float height)
:CObject(World,NULL),
x1(x1),
x2(x2),
y1(y1),
y2(y2),
width(width),
height(height)
{
  dMatrix3 R;
  
  #warning "Using inverted y-axis and heading"
  y1=-y1;
  y2=-y2;
  
  length=sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
  
  float dy=(y1-y2);
  float dx=(x1-x2);
  if (dy==0)
    angle =M_PI/2;
  else
    angle=atan(dx/dy);
  
  //box=new CBox(width, height, length,this,SpaceID,0,&WallMaterial,true);
  //"Walls are now placed in Space 1, where collisions are not checked!");
  box=new CBox(width, height, length,this,StaticSpaceID,0,&WallMaterial,true);
  
  dRFromAxisAndAngle(R, 0, 1, 0, angle);
  dGeomSetPosition(box->GeomID,(x1+x2)/2,height/2 + 0.0001,(y1+y2)/2);
  dGeomSetRotation(box->GeomID,R);
  
  
}

CWall::~CWall()
{
  delete box;
}

void CWall::Draw()
{
  box->Draw(std::string("models/textures/wall.png"));
}

void CWall::Update(float StepSize)
{
  
}

void CWall::OnCollision(CPrimitive *primitive, int numc, dContact *contacts, CPrimitive *primitive2)
{
  
}
